#encoding=utf8
'''
Created on 2012-10-18

@author: Administrator
'''

from dispatch.Processor import Processor
from pub import Func, UserDict, RoomDict;
from pub.Config import Config
class RIFAClass(Processor):
    '''
    指令：RIFA(room idiom found add) 邀请加入房间
    备注：邀请玩家游戏
    格式：c-s:cmd#cmdID#roomId#userId#userIdTo
     s-c:cmd#cmdID#roomId# roomTitle # userID# userNickName# userIDTO# userIDTONickName
    
    '''
    def __init__(self,):
        Processor.__init__(self,)
        self.__roomId = 0;
        self.__userId = 0;
        self.__userIdTo = 0;
        
    def dataValidtor(self, cmdContent):
        if not cmdContent:
            return False;
        paraLen = len(cmdContent);
        if paraLen == 3:      
            self.__roomId = Func.strToInt(cmdContent[0], Config.I_SYS_ZERO);
            self.__userId = Func.strToInt(cmdContent[1], Config.I_SYS_ZERO);
            self.__userIdTo = Func.strToInt(cmdContent[2], Config.I_SYS_ZERO);            
            return True;        
        return False;
    def outData(self,):
        room = RoomDict.getRoomFromDictById(self.__roomId);
        if not room:
            return False;
        userNickName = "";
        userToNickName = "";
        userSockt = None;
        userToSockt = None;
        user = UserDict.getUserFromUserDictById(self.__userId);
        if not user:
            userNickName = user.get_user_nick_name();
            userSockt = user.get_socket();
        user = None;
        user = UserDict.getUserFromUserDictById(self.__userIdTo);
        if not user:
            userToNickName = user.get_user_nick_name();
            userToSockt = user.get_socket();
        sendData = [];
        sendData.append(self.__roomId);
        sendData.append(room.get_room_name());
        sendData.append(self.__userId);
        sendData.append(userNickName);
        sendData.append(self.__userIdTo);
        sendData.append(userToNickName);
        sendStr = self.setPackage(sendData);
        userToSockt.sendLine(sendStr);       
        return True;
    
        
